﻿// JScript 文件

var url='<%=Url %>';
if(getPlayer(getExt(url))=="FLV"){document.write('<script type="text/javascript" src="/swf.js"></'+'script>');}
var agt = navigator.userAgent.toLowerCase();
var isIE = (agt.indexOf("msie") != -1);
function showInfo(player){
	var name={WMP:'<a href="http://www.baidu.com/s?wd=Windows+Media+Player" target="_blank">Windows Media Player</a>',RP:'<a target="_blank" href="http://www.baidu.com/s?wd=RealPlayer">RealPlayer</a>',QT:'<a target="_blank" href="http://www.baidu.com/s?wd=QuickTime">QuickTime</a>',Flash:'<a target="_blank" href="http://www.baidu.com/s?wd=Adobe+Flash+Player">Adobe Flash Player</a>'};
	document.getElementById('play_div').innerHTML='<table width="100%" height="100%"><tr><td vlign="middle" style="width:100%;height:100%;text-align:center;line-height:150%;font-weight:bold;background:#ecebff;">您的播放器不支持该视频<br>请安装'+name[player]+'播放器<br>或选择其它视频观看</td></tr></table>';
}
function getExt(u){
	u = u.split(/\?|#/)[0];
	return u.substr(u.lastIndexOf('.')+1);
}
function getPlayer(ex){
	var P={
	WMP:'asf,wmv,avi,mpeg,asx,dvr-ms,wpl,wm,wmx,wmd,wmz',
	RP:'rm,rmvb',
	QT:'mov'
	}
	if(ex.toLowerCase()=='flv'){
		return "FLV";
	};
	for(var i in P){
		var arr=P[i].split(',');
		for(var j=0;j<P[i].length;j++){
			if(ex==arr[j]) return i.toString();
		}
	}
	return 'WMP';
}
function showPlayer(url){
	var player=getPlayer(getExt(url));
	if(player=="FLV"){
		showFlv();
		return;
	}else if(dec(player)){
			DW(player,url);
		}else{
			showInfo(player);
		}
}
function dec(player){
	var result=false;
	if(isIE){
		var detkey = {WMP : "MediaPlayer.MediaPlayer.1", RP : "rmocx.RealPlayer G2 Control.1", QT : "QuickTimeCheckObject.QuickTimeCheck.1"};
		for(var k in detkey){
			if(k.toUpperCase()==player.toUpperCase()){
				try{
					var acx=new ActiveXObject(detkey[k]);
					result=true;
				}catch(e){}
			}
		}
	}else {
		var detkey = {wmp : "application/x-mplayer2", rp : "audio/x-pn-realaudio-plugin", qt : "video/quicktime"};
		for(var k in detkey){
			if(k.toUpperCase()==player.toUpperCase()){
				if (navigator.mimeTypes[detkey[k]].enabledPlugin != null)
					result=true;
			}
		}
	}
	return result;
}
function DW(player,url){
var html={
	WMP:['<object classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 width=100% height=100%>',
		'<param name=Filename value=',url,'>',
		'<param name=ShowStatusBar value=1>',
		'<param name=BufferingTime value=5>',
		'<embed filename=',url,' ShowStatusBar="1" type="application/x-mplayer2" ShowStatusBar="1" BufferingTime="5" width="100%" height="100%"></embed>',
		'</object>'
	],
	

	RP: [	'<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="100%" height="100%">',
	'<param name="AUTOSTART" value="1" />',
	'<param name="SRC" value="',url,'" />','<param name="CONTROLS" value="ImageWindow,ControlPanel,StatusBar" />',
	'<embed src="',url,'" type="audio/x-pn-realaudio-plugin" CONTROLS="ImageWindow,ControlPanel,StatusBar" autostart="true" width="100%" height="100%" />',
	'</object>'
		],

	QT: [	'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" width="100%" height="100%"> ',
	'<PARAM NAME="src" VALUE="',url,'" >',
	'<PARAM NAME="AutoPlay" VALUE="true" >',
	'<embed src="',	url,'"  type="video/quicktime" PLUGINSPAGE="http://www.apple.com/quicktime/download/" autoplay="true" width="100%" height="100%" />',
	'</object>'
		]
	};	
	document.getElementById('play_div').innerHTML=html[player].join('');
}
function showFlv(){
	var u=escape(url);
	var so=new SWFObject("/video.swf", "mm", "100%", "100%", 8, "#FFFFFF");
	so.addParam("quality", "high");
	so.addParam("swLiveConnect", "true");
	so.addParam("menu", "false");
	so.addParam("allowScriptAccess", "always");
	so.addParam("allowFullScreen", "true");
	so.addVariable("vid",u);
	if(deconcept.SWFObjectUtil.getPlayerVersion()["major"]>7)
		so.write("play_div");
	else
		showInfo("Flash");
}

function reshow(){
	if(getPlayer(getExt(url))!="FLV"){
		showPlayer(url);
	}
}